﻿using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ArchitectingInnovation.PRISMvvM.Core.Serialization
{
    public class XmlSerializer
    {
        public string Serialize<T>(T obj)
        {
            var serializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
            using (var writer = new StringWriter())
            {
                serializer.Serialize(writer, obj);
                return writer.GetStringBuilder().ToString();
            }


        }

        public T Deserialize<T>(string xml)
        {
            T instance = default(T);
            var serializer = new System.Xml.Serialization.XmlSerializer(typeof(T));

            using (StringReader reader = new StringReader(xml))
            {
                instance = (T)serializer.Deserialize(reader);
            }
            return instance;

        }
    }
}
